package com.jn.glide.presenter;

import android.content.Context;

import com.jn.glide.contract.MainContract;
import com.jn.glide.entity.EnglishEntity;
import com.jn.glide.service.MainService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainPresenter implements MainContract.IMainPresenter {
    private MainContract.IMainView mMainView;
    private Context mContext;

    public MainPresenter(MainContract.IMainView mMainView, Context mContext) {
        this.mMainView = mMainView;
        this.mContext = mContext;
    }

    @Override
    public void getData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.oioweb.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        MainService mainService = retrofit.create(MainService.class);
        mainService.getData().enqueue(new Callback<EnglishEntity>() {
            @Override
            public void onResponse(Call<EnglishEntity> call, Response<EnglishEntity> response) {
                EnglishEntity entity = response.body();
                mMainView.showData(entity);
            }

            @Override
            public void onFailure(Call<EnglishEntity> call, Throwable throwable) {

            }
        });

    }
}
